/*
 * Created by Wuwang on 2017/9/11
 * Copyright © 2017年 深圳哎吖科技. All rights reserved.
 */
package com.example.opengldemo._camera_demo.renderer;

import android.annotation.TargetApi;
import android.content.res.Resources;
import android.opengl.GLES11Ext;
import android.opengl.GLES30;
import android.os.Build;

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
public class OesFilter extends BaseFilter {

    public OesFilter(Resources resource) {
        super(resource,"camera/oes_vert.sh", "camera/oes_frag.sh");
    }

    public OesFilter(){
        super(null,
                "#version 300 es\n" +
                        "in vec4 aVertexCo;\n" +
                        "in vec2 aTextureCo;\n" +
                        "\n" +
                        "uniform mat4 uVertexMatrix;\n" +
                        "uniform mat4 uTextureMatrix;\n" +
                        "\n" +
                        "out vec2 vTextureCo;\n" +
                        "\n" +
                        "void main(){\n" +
                        "    gl_Position = uVertexMatrix*aVertexCo;\n" +
                        "    vTextureCo = (uTextureMatrix*vec4(aTextureCo,0,1)).xy;\n" +
                        "}",
                "#version 300 es\n" +
                        "#extension GL_OES_EGL_image_external_essl3 : require\n" +
                        "precision mediump float;\n" +
                        "\n" +
                        "in vec2 vTextureCo;\n" +
                        "uniform samplerExternalOES uTexture;\n" +
                        "\n" +
                        "layout(location=0) out vec4 fragColor;\n" +
                        "\n" +
                        "void main() {\n" +
                        "    fragColor = texture( uTexture, vTextureCo);\n" +
                        "}");
    }

    @Override
    protected void onBindTexture(int textureId) {
        GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
        GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,textureId);
        GLES30.glUniform1i(mGLTexture,0);
    }
}
